﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using UIWindow.Domains;
using UIWindow.Models;

namespace UIWindow.GlobalParameters
{
    [Attributes.Singleton]
    public class MainGlobal
    {
        public ObservableCollection<MenuModel> ContentList { get; set; }
        public ObservableCollection<DeviceStatusModel> DeviceLinkList { get; set; }
        public System.Threading.CancellationTokenSource SocketToken { get; set; }
        private MenuModel _selectedItem;

        public MenuModel SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                if (value != null && _selectedItem != value)
                {
                    _selectedItem = value;
                    Bootstrapper.Instance.ViewContext = Bootstrapper.GetContainer().ResolvePage(value.Name);
                }
            }
        }

        public MainGlobal()
        {
            ContentList = new ObservableCollection<MenuModel>();
            SocketToken = new System.Threading.CancellationTokenSource();
            DeviceLinkList = new ObservableCollection<DeviceStatusModel>();
        }

        public void UpdateMenu()
        {
            var container = Bootstrapper.GetContainer();
            ContentList.Clear();
            foreach (var item in container.GetMenuList(container.ResolveSingleton<UserGlobal>().LoginAuthority))
            {
                ContentList.Add(new MenuModel() { Name = item.Name, Icon = item.Icon });
            }
            SelectedItem = ContentList[0];
        }
    }
}
